package sdk.daum.dna.adapters;

import java.util.List;

import sdk.daum.dna.R;
import sdk.daum.dna.data.ArticleInfo;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ArticleAdapter extends ArrayAdapter<ArticleInfo> {

	public ArticleAdapter(Context context, List<ArticleInfo> objects) {
		super(context, R.layout.list_row_article, objects);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			LayoutInflater inflater = LayoutInflater.from(getContext());
			convertView = inflater.inflate(R.layout.list_row_article, null);

			convertView.setTag(R.id.tv_article_title, convertView.findViewById(R.id.tv_article_title));
			convertView.setTag(R.id.tv_article_blog_title, convertView.findViewById(R.id.tv_article_blog_title));
			convertView.setTag(R.id.tv_article_date, convertView.findViewById(R.id.tv_article_date));
		}

		ArticleInfo data = getItem(position);

		convertView.setTag(data);

		((TextView) convertView.getTag(R.id.tv_article_title)).setText(data.title);
		((TextView) convertView.getTag(R.id.tv_article_blog_title)).setText(data.blogTitle);
		((TextView) convertView.getTag(R.id.tv_article_date)).setText(data.date);

		return convertView;
	}

}